<!DOCTYPE HTML>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<link th:href="@{/ajax/libs/summernote/summernote.css}" rel="stylesheet"/>
<link th:href="@{/ajax/libs/summernote/summernote-bs3.css}" rel="stylesheet"/>

<body class="white-bg">
<style>
    .content{
        margin-top:6px ;
    }
    .form-group{
        margin-bottom: 0px;
    }
    #category1,#category2,#category3{
        border: none!important;
        appearance:noe!important;
        -moz-appearance:inherit;
        -webkit-appearance:inherit;
        background-color: transparent;
    }
    #area1,#area2,#area3{
        border: none!important;
        appearance:noe!important;
        -moz-appearance:inherit;
        -webkit-appearance:inherit;
        background-color: transparent;
    }
</style>

<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-shuixi-info" th:object="${shuixi}">
        <input id="sxId" name="sxId" th:field="*{sxId}"  type="hidden">
        <input id="sxRoleName" name="sxRoleName" th:field="*{sxRoleName}"  type="hidden">
        <div class="form-group">
            <label class="col-sm-3 control-label">标题：</label>
            <div class="col-sm-8">
                <div id="sxTitle" class="content" name="sxTitle" th:utext="*{sxTitle}" type="text"></div>
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-3 control-label">变更日期：</label>
            <div class="col-sm-8">
                <div id="sxNewChangedate" name="sxNewChangedate"  th:utext="*{sxNewChangedate}" class="content" type="text"></div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">创建者：</label>
            <div class="col-sm-8">
                <div id="createBy" name="createBy" th:utext="*{createBy}" class="content" type="text"></div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">创建日期：</label>
            <div class="col-sm-8">
                <div id="newcreateTime" name="newcreateTime" th:utext="*{newcreateTime}" class="content" type="text"></div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">更新者：</label>
            <div class="col-sm-8">
                <div id="updateBy" name="updateBy" th:utext="*{updateBy}" class="content" type="text"></div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">更新日期：</label>
            <div class="col-sm-8">
                <div id="newupdateTime" name="newupdateTime" th:utext="*{newupdateTime}" class="content" type="text"></div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">图片：</label>
            <div class="col-sm-8">
                <div id="sxProcess" name="sxProcess" th:utext="*{sxProcess}" class="content" type="text"></div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">审批状态：</label>
            <div class="col-sm-8">
                <div id="sxStatus" name="sxStatus" th:utext="*{sxStatus}" class="content" type="text"></div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">信息来源：</label>
            <div class="col-sm-8">
                <div id="sxOriginal" name="sxOriginal" th:utext="*{sxOriginal}" class="content" type="text"></div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">一级类别：</label>
            <div class="col-sm-8">
                <select id="category1"  class="content"  name="sxLb1"
                        data-rel="chosen" disabled="disabled">
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">二级类别：</label>
            <div class="col-sm-8">
                <select id="category2"  class="content"  name="sxLb2"
                        data-rel="chosen" disabled="disabled">
                </select>
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-3 control-label">三级类别：</label>
            <div class="col-sm-8" >
                <select id="category3"  class="content"  name="sxLb3"
                        data-rel="chosen" disabled="disabled">
                </select>
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-3 control-label">所在省：</label>
            <div class="col-sm-8">
                <select id="area1"  class="content"  name="sxProvince"
                        data-rel="chosen" disabled="disabled">
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">所在市：</label>
            <div class="col-sm-8">
                <select id="area2"  class="content"  name="sxCity"
                        data-rel="chosen" disabled="disabled">
                </select>
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-3 control-label">所在县：</label>
            <div class="col-sm-8" >
                <select id="area3"  class="content"  name="sxCountry"
                        data-rel="chosen" disabled="disabled">
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">批次：</label>
            <div class="col-sm-8">
                <div id="sxPici" name="sxPici" th:utext="*{sxPici}" class="content" type="text"></div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">审批机构：</label>
            <div class="col-sm-8">
                <div id="sxShenpijc" name="sxShenpijc" th:utext="*{sxShenpijc}" class="content" type="text"></div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">级别：</label>
            <div class="col-sm-8">
                <div id="sxLevels" name="sxLevels" th:utext="*{sxLevels}" class="content" type="text"></div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">详细内容：</label>
            <div class="col-sm-8">
                <div class="content" th:utext="*{sxDetails}"></div>
            </div>
        </div>
    </form>

</div>
<div th:include="include::footer"></div>
<script th:src="@{/ajax/libs/summernote/summernote.min.js}"></script>
<script th:src="@{/ajax/libs/summernote/summernote-zh-CN.js}"></script>
<script type="text/javascript" th:inline="javascript">
    var prefix = ctx + "system/shuixi";
    var prefix1 = ctx + "system/category"
    var prefix2 = ctx + "system/area"
    $(function() {

        var lb1 =   [[${shuixi.sxLb1}]];
        var lb2 =   [[${shuixi.sxLb2}]];
        var lb3 =   [[${shuixi.sxLb3}]];

        var szx1 =   [[${shuixi.sxProvince}]];
        var szx2 =   [[${shuixi.sxCity}]];
        var szx3 =   [[${shuixi.sxCountry}]];

        initCategrey(lb1,lb2,lb3);
        initArea(szx1,szx2,szx3);
        $('.summernote').summernote({
            height : '220px',
            lang : 'zh-CN',
            callbacks: {
                onImageUpload: function (files) {
                    sendFile(files[0], this);
                }
            }
        });
        var content = $("#sxDetails").val();
        $('#editor').summernote('code', content);
    });

    // 上传文件
    function sendFile(file, obj) {
        var data = new FormData();
        data.append("file", file);
        $.ajax({
            type: "POST",
            url: ctx + "common/upload",
            data: data,
            cache: false,
            contentType: false,
            processData: false,
            dataType: 'json',
            success: function(result) {
                if (result.code == web_status.SUCCESS) {
                    // $(obj).summernote('editor.insertImage', result.url, result.fileName);
                    $(obj).summernote('editor.insertImage', img_root + result.fileName, result.fileName);
                } else {
                    $.modal.alertError(result.msg);
                }
            },
            error: function(error) {
                $.modal.alertWarning("图片上传失败。");
            }
        });
    }
    $("#form-shuixi-info").validate({
        rules: {
            xxxx: {
                required: true,
            },
        }
    });

    function submitHandler() {
        if ($.validate.form()) {
            $.operate.save(prefix + "/info", $('#form-shuixi-info').serialize());
        }
    }

    function initCategrey(sxLb1,sxLb2,sxLb3) {


        cate1(sxLb1);
        cate2(sxLb1,sxLb2);
        cate3(sxLb2,sxLb3);
        $("#category1").change(function () {
            cate2($("#category1").val());

        });
        $("#category2").change(function () {
            cate3($("#category2").val());
        });

    }
    function cate1(id) {
        $.get(
            prefix1 + "/list?parentId=100&deptId=6",
            function (data) {
                if (data) {
                    var result = "";
                    $.each(data, function (n, value) {

                        if(value.deptId ==id )
                            result += "<option selected= 'true' value='" + value.deptId + "'>" + value.deptName + "</option>";
                        else
                            result += "<option value='" + value.deptId + "'>" + value.deptName + "</option>";

                    });
                    $("#category1").html(result);
                }
            }, "json");
    }

    function cate2(id,deptId) {
        $.get(
            prefix1 + "/list?parentId=6",
            function (data) {
                if (data) {
                    var result = "";
                    $.each(data, function (n, value) {

                        if(value.deptId ==deptId )
                            result += "<option selected= 'true' value='" + value.deptId + "'>" + value.deptName + "</option>";
                        else
                            result += "<option value='" + value.deptId + "'>" + value.deptName + "</option>";

                    });
                    $("#category2").html(result);

                }
            }, "json");
    }
    function cate3(id,deptId) {
        $.get(
            prefix1 + "/list?parentId=" + id ,
            function (data) {
                if (data) {
                    var result = '';
                    $.each(data, function (n, value) {
                        if(value.deptId ==deptId )
                            result += "<option selected= 'true' value='" + value.deptId + "'>" + value.deptName + "</option>";
                        else
                            result += "<option value='" + value.deptId + "'>" + value.deptName + "</option>";
                    });

                    $("#category3").html(result);
                }
            }, "json");
    }

    function initArea(sxProvince,sxCity,sxCountry) {


        farea1(sxProvince);
        farea21(sxProvince,sxCity);
        farea3(sxCity,sxCountry);
        $("#area1").change(function () {
            farea2($("#area1").val());

        });
        $("#area2").change(function () {
            farea3($("#area2").val());
        });

    }
    function farea1(id) {
        $.get(
            prefix2 + "/list?parentId=1",
            function (data) {
                if (data) {
                    var result = "";
                    $.each(data, function (n, value) {

                        if(value.deptId ==id )
                            result += "<option selected= 'true' value='" + value.deptId + "'>" + value.deptName + "</option>";
                        else
                            result += "<option value='" + value.deptId + "'>" + value.deptName + "</option>";

                    });
                    $("#area1").html(result);
                }
            }, "json");
    }

    function farea2(id,deptId) {
        $.get(
            prefix2 + "/list?parentId="+ id,
            function (data) {
                if (data) {
                    var result = "";
                    $.each(data, function (n, value) {


                        if(value.deptId ==deptId )
                        {
                            result += "<option selected= 'true' value='" + value.deptId + "'>" + value.deptName + "</option>";
                        }
                        else
                        {
                            result += "<option value='" + value.deptId + "'>" + value.deptName + "</option>";
                            if(n==0)
                            {
                                farea3(value.deptId);
                            }
                        }
                    });
                    $("#area2").html(result);

                }
            }, "json");
    }

    function farea21(id,deptId) {
        $.get(
            prefix2 + "/list?parentId="+ id,
            function (data) {
                if (data) {
                    var result = "";
                    $.each(data, function (n, value) {


                        if(value.deptId ==deptId )
                        {
                            result += "<option selected= 'true' value='" + value.deptId + "'>" + value.deptName + "</option>";
                        }
                        else
                        {
                            result += "<option value='" + value.deptId + "'>" + value.deptName + "</option>";
                        }
                    });
                    $("#area2").html(result);

                }
            }, "json");
    }

    function farea3(id,deptId) {
        $.get(
            prefix2 + "/list?parentId=" + id ,
            function (data) {
                if (data) {
                    var result = '';
                    $.each(data, function (n, value) {
                        if(value.deptId ==deptId )
                            result += "<option selected= 'true' value='" + value.deptId + "'>" + value.deptName + "</option>";
                        else
                            result += "<option value='" + value.deptId + "'>" + value.deptName + "</option>";
                    });

                    $("#area3").html(result);
                }
            }, "json");
    }

</script>
</body>
</html>
